package adpater;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.example.a513.R;

import java.util.ArrayList;
import java.util.List;

public class LauncherAdapter extends PagerAdapter {
    private List<View> imageViews = new ArrayList<>();
    private Context context;
    public LauncherAdapter(Context context,int []arr){

        for (int i = 0; i< arr.length; i++){
            View view = LayoutInflater.from(context).inflate(R.layout.item_launch, null);
            ImageView imgview =
                    view.findViewById(R.id.iv_launcher);
            RadioGroup rd_group = view.findViewById(R.id.radio_group);
            Button btn_start = view.findViewById(R.id.btn_start);
            imgview.setImageResource(arr[i]);
            for (int j = 0; j < arr.length; j++){
                RadioButton radioButton = new RadioButton(context);
                radioButton.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,RadioGroup.LayoutParams.WRAP_CONTENT));
                radioButton.setPadding(30,30,30,30);
                rd_group.addView(radioButton);


            }
            ((RadioButton) rd_group.getChildAt(i)).setChecked(true);

            if (i == arr.length -1){
                btn_start.setVisibility(View.VISIBLE);
                btn_start.setOnClickListener(v-> Toast.makeText(context,"welcom",Toast.LENGTH_LONG).show());
            }
            imageViews.add(view);
        }

    }

    @Override
    public int getCount() {
        return imageViews.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View imageView = imageViews.get(position);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(imageViews.get(position));
    }
}
